package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.admin.api.dto.RoleAuthorityAreaDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.RoleAuthorityAreaRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色权限区域查询
 *
 * @author wangchlei
 * @date 2020/09/03
 */
@Service
@Slf4j
public class RoleAuthorityAreaFacade {
    @Resource
    private RoleAuthorityAreaRemote roleAuthorityAreaRemote;

    /**
     * 根据用户id查看用户的区域权限(直营渠道)
     *
     * @param userId
     * @return {@link List<RoleAuthorityAreaDTO>}
     **/
    public List<RoleAuthorityAreaDTO> getRoleAuthorityAreaByUserId(Long userId) {
        log.info("根据用户id查看用户的区域权限(直营渠道)入参:userId:{}", JSON.toJSONString(userId));
        Response<List<RoleAuthorityAreaDTO>> response = roleAuthorityAreaRemote.getRoleAuthorityAreaByUserId(userId);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
